package com.example.mac.yuejian14.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import com.example.mac.yuejian14.R;
import com.example.mac.yuejian14.activity.TeacherDetailActivity;
import com.example.mac.yuejian14.bean.TeacherBean;

/**
<<<<<<< HEAD
 * Created by Administrator on 2017/10/25.
 */

=======
 * Created by GaoNa on 2018/10/8.
 */
>>>>>>> 4629567011ce192c56b08540254859f8a556460d
public class TeacherListAdapter extends RecyclerView.Adapter <RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflaterp;

    public TeacherListAdapter(Context mContext,List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflaterp = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View v =mLayoutInflaterp.from(parent.getContext())
                    .inflate(R.layout.cardview_teacher, parent, false);
            return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final TeacherBean entity = (TeacherBean) mDataList.get(position);
        if (null == entity)
            return;
        //绑定数据
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.proname.setText(entity.getTeachname());
        viewHolder.protype.setText(entity.getTeachintro());
        String professor_imageBtn = "http://10.0.2.2/neu12_yuejian/Public/Uploads/photo/"+entity.getTeachpic();

        if (!professor_imageBtn.equals("")){
            Picasso.with(mContext).load(professor_imageBtn).error(R.drawable.no_pic).into(viewHolder.imagepro);
        }
        //点击item跳转
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putInt("teachid",entity.getTeachid());
                bundle.putString("teachname",entity.getTeachname());
                bundle.putString("teachpic",entity.getTeachpic());
                bundle.putInt("clubid",entity.getClubid());
                bundle.putString("teachintro",entity.getTeachintro());
                Intent intent=new Intent(mContext, TeacherDetailActivity.class);
                intent.putExtras(bundle);
                mContext.startActivity(intent);

            }
        });

    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView imagepro;
        TextView proname;
        TextView protype;
        public ViewHolder(View itemView) {
            super(itemView);
            proname = (TextView) itemView.findViewById(R.id.teacher_name);
            imagepro = (ImageView) itemView.findViewById(R.id.teacher_imageBtn);
            protype = (TextView) itemView.findViewById(R.id.teacher_type);

        }
    }
}
